<%@ include file="database_ini.jsp"%>
<%@page contentType="text/html; charset=UTF-8"%>
  <%@page import="org.json.*"%>
  <%
  	System.out.println("started:.....");
  	
  	String sql =null;
  	ResultSet rs =null;
  	String dropid = request.getParameter("dropid");
  	/*********debug*/
  	System.out.println(dropid);
  	
  	/****************/
  	System.out.println("ok?");
  	/****************/
  	
  	JSONObject obj=new JSONObject();
  	
  	/****************/
  	JSONArray jsonChildarray = new JSONArray();
  	
  	/*
  	sql = "select CCHDR.Status from CCDET, CCHDR where CCDET.CCDROPID =  ? and CCDET.CCKEY = CCDET.CCKEY";
  	
  	pstmt = conn.prepareStatement(sql);
  	pstmt.setString(1 , dropid);
  	
  	ResultSet rs_CCDROPID = pstmt.executeQuery();
  	if (rs_CCDROPID.next() ) {
	*/
		
	  	
	  	//sql = "select Status, CCDROPID, Seq, Loc, Sku, Descr, UPCCode, Lottable05, Casecnt, DisplaySystemCount, Qty as Qty from CCDET WHERE CCDROPID = ? ";
	  	sql = "select Status, CCDROPID, Seq, Loc, Sku, Descr, UPCCode, Lottable05, Casecnt, DisplaySystemCount, sum(Qty) as Qty from CCDET WHERE CCDROPID = ? "
	  	+ "group by Status, CCKEY, CCDROPID, Seq, Loc, Sku, Descr, UPCCode, Lottable05, Casecnt, DisplaySystemCount";
	  	
	  	String Status = "-1";
	  	pstmt = conn.prepareStatement(sql);
	  	pstmt.setString(1 , dropid);
	  	
	  	rs = pstmt.executeQuery();
	  	while (rs.next()) {
	  		Status = rs.getString("Status");
			String Seq = rs.getString("Seq");
	  		String Loc = rs.getString("Loc");
	  		String Sku = rs.getString("Sku");
	  		String Descr = rs.getString("Descr");
	  		String UPCCode = rs.getString("UPCCode");
	  		String Lottable05 = rs.getString("Lottable05");
	  		String Casecnt = rs.getString("Casecnt");
	  		String DisplaySystemCount = rs.getString("DisplaySystemCount");
	  		String Qty = " ";
	  		if("1".equalsIgnoreCase(DisplaySystemCount)){
	  			Qty = rs.getString("Qty");
	  		}
	  		
	  		/****************/
	  		System.out.println("Status:" + Status);
	  		System.out.println("Seq:" + Seq);
	  		System.out.println("Loc:" + Loc);
	  		System.out.println("Sku:" + Sku);
	  		System.out.println("Descr:" + Descr);
	  		System.out.println("UPCCode:" + UPCCode);
	  		System.out.println("Lottable05:" + Lottable05);
	  		System.out.println("Casecnt:" + Casecnt);
	  		System.out.println("DisplaySystemCount:" + DisplaySystemCount);
	  		System.out.println("Qty:" + Qty);
	  		/****************/
	  		
	  		if("0".equalsIgnoreCase(Status)){
		  		JSONObject child = new JSONObject();
		  		child.put("Seq", Seq);
		  		child.put("Loc", Loc);
		  		child.put("Sku", Sku);
		  		child.put("Descr", Descr);
		  		child.put("UPCCode", UPCCode);
		  		child.put("Lottable05", Lottable05);
		  		child.put("Casecnt", Casecnt);
		  		child.put("Qty", Qty);
		  		if("0".equals(Status)){
		  			jsonChildarray.put(child);
				}
			}
	  	}

	obj.put("Status", Status);
  	obj.put("jsonChildarray", jsonChildarray);
  	/****************/

  	out.print(obj);
  	System.out.println(obj);
  	out.flush();

  	conn.close();
  %>